package com.ass.llm.chat.factory;

import com.ass.llm.chat.LLMChatAbstract;
import com.ass.llm.constant.LLMEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class LLMFactory {


    private final Map<LLMEnum, LLMChatAbstract> llmMap = new HashMap<>();


    @Autowired
    public LLMFactory(List<LLMChatAbstract> llm) {
        for (LLMChatAbstract chatAbstract : llm) {
            llmMap.put(chatAbstract.getLLm(), chatAbstract);
        }
    }

    public LLMChatAbstract getLLMEnum(LLMEnum llmEnum) {
        return llmMap.get(llmEnum);
    }

    /**
     * @describe：小写获得LLM
     * @author：李勇
     * @date：2025/6/22
     * @param lowercase
     * @return：com.sx.llm.chat.LLMChatAbstract
     */
    public LLMChatAbstract getLLMByLower(String lowercase) {
        LLMEnum llmEnum = LLMEnum.getLLMEnumByLower(lowercase);
        if (llmEnum == null) {
            throw new IllegalArgumentException("Invalid code: " + lowercase);
        }
        return getLLMEnum(llmEnum);
    }

    /**
     * @describe：大写获得LLM
     * @author：李勇
     * @date：2025/6/22
     * @param uppercase
     * @return：com.sx.llm.chat.LLMChatAbstract
     */
    public LLMChatAbstract getLLMByUpper(String uppercase) {
        LLMEnum llmEnum = LLMEnum.getLLMEnumByUpper(uppercase);
        if (llmEnum == null) {
            throw new IllegalArgumentException("Invalid code: " + uppercase);
        }
        return getLLMEnum(llmEnum);
    }


}
